package com.servlet;





import com.entity.Dto;
import com.service.FindService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/FindServlet")
public class FindServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String goodsName = request.getParameter("goodsName");
        System.out.println(goodsName);
        Dto dto = new Dto();
        dto.setGoodsName(goodsName);
        int displayCount=3,page=1,maxPage=0;
        FindService findService = new FindService();
        maxPage = findService.displayPage(dto,displayCount);
        System.out.println("maxpage为"+maxPage);
        if (request.getParameter("page") !=null){
            int p = Integer.parseInt(request.getParameter("page"));
            if (p<1){
                p=1;
            }
            if(p>maxPage){
                p=maxPage;
            }
            page=p;
        }
        List<Dto> GoodsList = findService.laodAllFind(dto,page,displayCount);
        request.getSession().setAttribute("GoodsList",GoodsList);
        for(Dto a:GoodsList){
            System.out.println(a.toString());
        }
        response.sendRedirect("cakeName.jsp");
    }

}